Proximity-based addressing for supporting in-place execution in virtual machines

ABSTRACT

One embodiment of the present invention provides a system that facilitates performing proximity-based addressing in a platform-independent virtual machine. During execution of a program on the platform-independent virtual machine, the system receives an instruction and a parameter associated with the instruction that can be used to generate a reference to a program element associated with the instruction. Next, the system examines information encoded within the parameter to determine a proximity of the reference, and then uses the parameter to generate the reference to the program element, wherein the proximity of the reference determines how the reference is generated from the parameter.

BACKGROUND

[0001] 1. Field of the Invention

[0002] The present invention relates to the design ofplatform-independent virtual machines within computer systems. Morespecifically, the present invention relates to a method and an apparatusfor performing proximity-based addressing to support in-place executionin platform-independent virtual machines.

[0003] 2. Related Art

[0004] Dramatic advances in computer technology presently make itpossible to integrate a significant amount of computing power intopocket-sized computing devices, such as cell phones and personalorganizers. In order to enable these devices to run a wide variety ofapplications, developers have begun to incorporate platform-independentvirtual machines (such as the JAVA VIRTUAL MACHINET™ developed by SUNMicrosystems, Inc. of Santa Clara, Calif.) into these computing devices.This enables these computing devices to execute platform-independentbytecodes, which can be easily distributed to a large number ofdifferent computing platforms.

[0005] In particular, the Java 2 Platform, Micro Edition (J2ME™) hasbecome very popular in the wireless device space. Many key players inthe wireless device industry have recently started shipping J2ME-enableddevices in high volume. It has been estimated that 60-80 millionJ2ME-enabled mobile phones were shipped in 2002, and the total number ofJ2ME devices shipped in 2003 is likely to exceed 200 million. In spiteof the success of the J2ME platform, significant challenges for JAVA™technology remain in the small device space.

[0006] One area that is becoming a big bottleneck for serious J2MEapplication development is—not surprisingly—application size. With thedeployment of more significant J2ME applications in mobile devices, J2MEapplication downloads consume an increasingly larger amount of wirelessnetwork bandwidth. Also, the runtime dynamic memory costs andapplication startup costs associated with anything but very small J2MEapplications are still excessive for most mass-market consumer devices,as well as for serious mobile systems software development in the Javaprogramming language.

[0007] One of the most promising approaches reducing the memory usageand application startup costs in platform-independent virtual machinesis a technique known as “in-place execution.” In a Java Virtual Machine(JVM) that supports pure in-place execution, the standard Java classfile format is replaced with a representation that can be used directlyas runtime structures for the virtual machine, without the conventional,costly class loading process. In this representation, static datastructures, such as classes, method tables, field tables, exceptionhandlers, symbols, constants and byte codes, are never actually loadedinto the virtual machine, but are instead accessed directly from thestatic representation. In mobile devices, where the staticrepresentation can be kept in cheap flash or read-only memory, this canimply dramatic RAM consumption savings; up to 5-10 X in commonsituations. The static size of applications can also be significantlysmaller than with regular Java class files or JAR files, without anyloss of symbolic information or dynamic linkability of Javaapplications.

[0008] Unfortunately, in-place execution has a number of disadvantageswhen it comes to execution speed. Since in-place executable code isimmutable, various commonly used runtime optimizations that depend onthe ability to modify bytecodes at runtime cannot be used. Also, sincein-place executable files are intended to be easily relocatable inmemory, all references in such files must be offsets rather thanpointers. This introduces an additional level of indirection at runtime,which slows down execution speed.

[0009] Additionally, since in-place executable files are generallyintended to be applicable to a broad number of virtual machineimplementations, they cannot be customized for particular virtualmachine implementations like the run-time data structures that are usedin conventional virtual machines.

[0010] Because of these problems, in-place execution has not been widelyused in platform-independent virtual machines, even though suchtechnology would otherwise be ideal for mobile phones and other targetdevices.

[0011] Hence, what is needed is a method and an apparatus thatfacilitates efficiently performing in-place execution inplatform-independent virtual machines.

SUMMARY

[0012] One embodiment of the present invention provides a system thatfacilitates performing proximity-based addressing in aplatform-independent virtual machine. During execution of a program onthe platform-independent virtual machine, the system receives aninstruction and a parameter associated with the instruction that can beused to generate a reference to a program element associated with theinstruction. Next, the system examines information encoded within theparameter to determine a proximity of the reference, and then uses theparameter to generate the reference to the program element, wherein theproximity of the reference determines how the reference is generatedfrom the parameter.

[0013] In a variation on this embodiment, the proximity of the referencecan indicate that: the program element is located in the same class; theprogram element is associated with another class in the same bundle; orthe program element is associated with another class in another bundle.

[0014] In a variation on this embodiment, if the program element is afield or a method, and if the proximity of the reference indicates thatthe program element is located in the same class, generating thereference involves using the parameter as an offset for the programelement within the same class.

[0015] In a variation on this embodiment, if the program element is afield or a method, and if the proximity of the reference indicates thatthe program element is located in another class in the same bundle,generating the reference involves using the parameter to lookup an entryin a reference lookup structure, wherein the entry contains a globaloffset for the class, and an offset for the program element within theclass.

[0016] In a variation on this embodiment, if the program element is afield or a method, and if the proximity of the reference indicates thatthe program element is located in another class in another bundle,generating the reference involves using the parameter to lookup an entryin a reference lookup structure, wherein the entry identifies a classname, a program element name and a program element type. Next, thesystem uses the class name to lookup a global offset for the class, anduses the program element name and the program element type to look up anoffset for the program element within the class.

[0017] In a variation on this embodiment, if the program element is aclass, and if the proximity of the reference indicates that the class islocated in the same bundle, generating the reference involves using theparameter to lookup an entry in a reference lookup structure, whereinthe entry contains a global offset for the class.

[0018] In a variation on this embodiment, if the program element is alass, and if the proximity of the reference indicates that the class islocated in another bundle, generating the reference involves using theparameter to lookup an entry in a reference lookup structure, whereinthe entry identifies a class name. Next, the system uses the class nameto lookup a global offset for the class.

[0019] In a variation on this embodiment, prior to execution of theprogram, the system produces a reference lookup structure to facilitategenerating references to program elements during in-place execution. Ina further variation, the reference lookup structure includes, areference table for generating references to methods or fields, and anoffset map for generating references to classes.

[0020] In a variation on this embodiment, the information encoded withinthe parameter is contained in reserved bits, which comprise the twolowest-order bits of the parameter.

BRIEF DESCRIPTION OF THE FIGURES

[0021]FIG. 1 illustrates the execution of a platform-independentapplication on a computing device.

[0022]FIG. 2 illustrates in-place execution of a platform-independentapplication on a computing device in accordance with an embodiment ofthe present invention.

[0023]FIG. 3 illustrates a bytecode and an associated parameter.

[0024]FIG. 4 illustrates lookup structures that facilitate usingoffset-based references in accordance with an embodiment of the presentinvention.

[0025]FIG. 5 presents a flow chart illustrating the proximity-basedaddressing process in accordance with an embodiment of the presentinvention.

DETAILED DESCRIPTION

[0026] The following description is presented to enable any personskilled in the art to make and use the invention, and is provided in thecontext of a particular application and its requirements. Variousmodifications to the disclosed embodiments will be readily apparent tothose skilled in the art, and the general principles defined herein maybe applied to other embodiments and applications without departing fromthe spirit and scope of the present invention. Thus, the presentinvention is not intended to be limited to the embodiments shown, but isto be accorded the widest scope consistent with the principles andfeatures disclosed herein.

[0027] The data structures and code described in this detaileddescription are typically stored on a computer readable storage medium,which may be any device or medium that can store code and/or data foruse by a computer system. This includes, but is not limited to, magneticand optical storage devices such as disk drives, magnetic tape, CDs(compact discs) and DVDs (digital versatile discs or digital videodiscs), and computer instruction signals embodied in a transmissionmedium (with or without a carrier wave upon which the signals aremodulated). For example, the transmission medium may include acommunications network, such as the Internet.

[0028] Executing a Platform-Independent Application on a ComputingDevice

[0029]FIG. 1 illustrates conventional execution of aplatform-independent application on a computing device 102. Computingdevice 102 can generally include any type of device or system withcomputational capabilities, including, but not limited to, a laptopcomputer system, a pocket-sized computer system, a personal organizer ora device controller. Computing device 102 can also include a computingdevice that is embedded within another device, such as a pager, a cellphone, a television, an automobile, or an appliance. In one embodimentof the present invention, computing device 102 includes a wirelesstransceiver for sending and receiving signals across a wireless network.

[0030] During operation, computing device 102 can receive aplatform-independent application. For example, referring to FIG. 1computing device 102 receives a platform-independent applicationcontained in a Java ARchive file (JAR file) 108, or in some otherequivalent file format. The application within JAR file 108 is made upof a number of class files and other data structures.

[0031] JAR file 108 is loaded into non-volatile flash memory 104 (orread-only memory) within computing device 102. This loading process cantake place over a wireless or a wired communication link, or byintroduction of a computer-readable storage medium, such as a disk,containing JAR file 204 into computing device 102.

[0032] Next, in order to execute the application, a time-consuming classloading process takes place in which static data structures 110(application metadata) are copied from flash memory 104 into randomaccess memory (RAM) 106. These static data structures 110 includesitems, such as classes, field and method tables, symbols, exceptionhandler tables, constants and bytecodes. Additionally, dynamic datastructures 112 associated with the application (such as objectinstances, execution stacks, threads and monitors) are stored in RAM106. The application can then be executed in RAM 106.

[0033] Note that the time-consuming process of copying static datastructures 110 and code into RAM 106 is largely unnecessary because itis possible to access the static data structures 110 and code directlyfrom flash memory 104.

[0034] In-Place Execution of a Platform-Independent Application

[0035]FIG. 2 illustrates in-place execution of a platform-independentapplication on computing device 102 in accordance with an embodiment ofthe present invention. In this embodiment, a converter 202 processes JARfile 108 to produce a converted JAR file 204. Within converted JAR file108, all static data structures of the application (applicationmetadata) are represented in directly executable form.

[0036] Next, converted JAR file 108 is loaded in flash memory 104 withincomputing device 102. When the application is subsequently executed, thestatic data structures stay within flash memory 104. Only small “shadowclasses” 206, which act as placeholders for static variables, are storedin RAM 106 along with dynamic data structures 112.

[0037] Bytecode Format

[0038] During the above-described conversion process, pointers arereplaced by offsets to allow the application to be relocated in memory.During this conversion process, the bytecode format is largelyunchanged. Note that it is possible to change the bytecode format tosupport offset-based addressing. However, modifying the bytecode formatmakes it hard if not impossible to use existing debugging tools. Hence,it is desirable to preserve the bytecode format (and in particular thelengths of bytecodes) when performing the conversion.

[0039] A bytecode is often associated with a parameter, which can beused to determine the location of a program element (such as a method, afield or a class) associated with the bytecode. During the conversionprocess, parameters containing pointers are converted into eitheroffsets or symbolic links.

[0040] Reserved bits in the bytecode are used to specify which how areference to the program element is to be generated from the parameter.For example, referring to FIG. 3, an 8-bit bytecode 302 is associatedwith an adjacent 16-bit parameter 304. The two lower-order two bits ofparameter 304 function as reserved bits 306, which specify how thereference to the program element is to be generated from the parameteras is described in more below with reference to FIGS. 4-5.

[0041] Lookup Structures to Support Offset-Based Addressing

[0042] Parameter 304 is used to reference one or more lookup structurescontaining offsets or symbolic links. For example, FIG. 4 depicts lookupstructures that facilitate offset-based references in accordance with anembodiment of the present invention. These lookup structures includereference table 402 and offset map 420.

[0043] Referring to the flow chart in FIG. 5, reference table 402 andoffset map 420 are used as follows. During execution of aplatform-independent application, a platform-independent virtual machinereceives a bytecode 302 along with an associated parameter 304 that canbe used to generate a reference to a program element associated withbytecode 302 (step 502).

[0044] Next, the system examines reserved bits 306 within parameter 304to determine the proximity of the reference (step 504). The system alsoexamines the bytecode to determine the type of the program element(field, method, class) (step 506). Next, the system performs a number ofactions depending on the type of the program element and the proximityof the reference.

[0045] If the program element is a field or a method and if theproximity of the reference is the same class (indicated by reserved bits00), parameter 304 is used as an offset into the class, and no lookup isrequired (step 508).

[0046] If the program element is a field or a method and if theproximity of the reference is to another class in the same bundle(indicated by reserved bits 01), parameter 304 is used to lookup anentry 401 in reference table 402. (Note that this lookup, as well asother lookups in reference table 402 and offset map 420, may involvemasking out reserved bits 306.) Entry 401 contains an unused 32-bit word403, a global 32-bit class offset 404 for a corresponding class 412, anda 16-bit field/method offset 405, which specifies an offset for thefield or method within class 412 (step 510).

[0047] If the program element is a field or a method and if theproximity of the reference is to another class in another bundle(indicated by reserved bits 10), parameter 304 is used to lookup anentry 415 in reference table 402. Entry 415 contains a class name offset406, a field/method name offset 407 and a signature 408. Class nameoffset 406 is used to lookup a class name in global symbol pool 414.This class name is used to perform a system lookup 416, which returns aglobal 32-bit class offset 418 for a corresponding class 413.Field/method name offset 407 is similarly used to lookup a field/methodname in global symbol pool 414. This field/method name along withsignature 408 are used to perform a system lookup, which returns a16-bit offset for the field/method within class 412 (step 512).

[0048] If the program element is a class and if the proximity of thereference is the same bundle or file (indicated by reserved bits 01),parameter 304 is used to lookup an entry 421 in offset map 420, whereinentry 421 contains a 32-bit global class offset 422 for a correspondingclass (step 514).

[0049] If the program element is a class and if the proximity of thereference is another bundle or file (indicated by reserved bits 10),parameter 304 is used to lookup an entry 423 in offset map 420. Entry423 contains a class name offset 424, which is used to lookup a classname in global symbol pool 414. This class name is used to perform asystem lookup, which returns a 32-bit global class offset for acorresponding class (step 516).

[0050] The foregoing descriptions of embodiments of the presentinvention have been presented for purposes of illustration anddescription only. They are not intended to be exhaustive or to limit thepresent invention to the forms disclosed. Accordingly, manymodifications and variations will be apparent to practitioners skilledin the art. Additionally, the above disclosure is not intended to limitthe present invention. The scope of the present invention is defined bythe appended claims.

What is claimed is:
 1. A method for performing proximity-basedaddressing in a platform-independent virtual machine, comprising:receiving an instruction during execution of a program on theplatform-independent virtual machine; receiving a parameter associatedwith the instruction that can be used to generate a reference to aprogram element associated with the instruction; examining informationencoded within the parameter to determine a proximity of the reference;and using the parameter to generate the reference to the programelement, wherein the proximity of the reference determines how thereference is generated from the parameter.
 2. The method of claim 1,wherein the proximity of the reference can indicate that: the programelement is located in the same class; the program element is associatedwith another class in the same bundle; or the program element isassociated with another class in another bundle.
 3. The method of claim2, wherein if the program element is a field or a method, and if theproximity of the reference indicates that the program element is locatedin the same class, generating the reference involves: using theparameter as an offset for the program element within the same class. 4.The method of claim 2, wherein if the program element is a field or amethod, and if the proximity of the reference indicates that the programelement is located in another class in the same bundle, generating thereference involves: using the parameter to lookup an entry in areference lookup structure, wherein the entry contains a global offsetfor the class, and an offset for the program element within the class.5. The method of claim 2, wherein if the program element is a field or amethod, and if the proximity of the reference indicates that the programelement is located in another class in another bundle, generating thereference involves: using the parameter to lookup an entry in areference lookup structure, wherein the entry identifies a class name, aprogram element name and a program element type; using the class name tolookup a global offset for the class; and using the program element nameand the program element type to look up an offset for the programelement within the class.
 6. The method of claim 2, wherein if theprogram element is a class, and if the proximity of the referenceindicates that the class is located in the same bundle, generating thereference involves: using the parameter to lookup an entry in areference lookup structure, wherein the entry contains a global offsetfor the class.
 7. The method of claim 2, wherein if the program elementis a class, and if the proximity of the reference indicates that theclass is located in another bundle, generating the reference involves:using the parameter to lookup an entry in a reference lookup structure,wherein the entry identifies a class name; and using the class name tolookup a global offset for the class.
 8. The method of claim 1, whereinprior to execution of the program, the method further comprisesproducing a reference lookup structure to facilitate generatingreferences to program elements during in-place execution.
 9. The methodof claim 8, wherein the reference lookup structure includes: a referencetable for generating references to methods or fields; and an offset mapfor generating references to classes.
 10. The method of claim 1, whereinthe information encoded within the parameter is contained in reservedbits, wherein the reserved bits are the two lowest-order bits of theparameter.
 11. A computer-readable storage medium storing instructionsthat when executed by a computer cause the computer to perform a methodfor performing proximity-based addressing in a platform-independentvirtual machine, the method comprising: receiving an instruction duringexecution of a program on the platform-independent virtual machine;receiving a parameter associated with the instruction that can be usedto generate a reference to a program element associated with theinstruction; examining information encoded within the parameter todetermine a proximity of the reference; and using the parameter togenerate the reference to the program element, wherein the proximity ofthe reference determines how the reference is generated from theparameter.
 12. The computer-readable storage medium of claim 11, whereinthe proximity of the reference can indicate that: the program element islocated in the same class; the program element is associated withanother class in the same bundle; or the program element is associatedwith another class in another bundle.
 13. The computer-readable storagemedium of claim 12, wherein if the program element is a field or amethod, and if the proximity of the reference indicates that the programelement is located in the same class, generating the reference involves:using the parameter as an offset for the program element within the sameclass.
 14. The computer-readable storage medium of claim 12, wherein ifthe program element is a field or a method, and if the proximity of thereference indicates that the program element is located in another classin the same bundle, generating the reference involves: using theparameter to lookup an entry in a reference lookup structure, whereinthe entry contains a global offset for the class, and an offset for theprogram element within the class. 15 The computer-readable storagemedium of claim 12, wherein if the program element is a field or amethod, and if the proximity of the reference indicates that the programelement is located in another class in another bundle, generating thereference involves: using the parameter to lookup an entry in areference lookup structure, wherein the entry identifies a class name, aprogram element name and a program element type; using the class name tolookup a global offset for the class; and using the program element nameand the program element type to look up an offset for the programelement within the class.
 16. The computer-readable storage medium ofclaim 12, wherein if the program element is a class, and if theproximity of the reference indicates that the class is located in thesame bundle, generating the reference involves: using the parameter tolookup an entry in a reference lookup structure, wherein the entrycontains a global offset for the class.
 17. The computer-readablestorage medium of claim 12, wherein if the program element is a class,and if the proximity of the reference indicates that the class islocated in another bundle, generating the reference involves: using theparameter to lookup an entry in a reference lookup structure, whereinthe entry identifies a class name; and using the class name to lookup aglobal offset for the class.
 18. The computer-readable storage medium ofclaim 11, wherein prior to execution of the program, the method furthercomprises producing a reference lookup structure to facilitategenerating references to program elements during in-place execution. 19.The computer-readable storage medium of claim 18, wherein the referencelookup structure includes: a reference table for generating referencesto methods or fields; and an offset map for generating references toclasses.
 20. The computer-readable storage medium of claim 11, whereinthe information encoded within the parameter is contained in reservedbits, wherein the reserved bits are the two lowest-order bits of theparameter.
 21. An apparatus for performing proximity-based addressing ina platform-independent virtual machine, comprising: aplatform-independent virtual machine configured to execute aplatform-independent program; a receiving mechanism within theplatform-independent virtual machine configured to receive, aninstruction, and a parameter associated with the instruction that can beused to generate a reference to a program element associated with theinstruction; and a reference generation mechanism configured to, examineinformation encoded within the parameter to determine a proximity of thereference, and to use the parameter to generate the reference to theprogram element, wherein the proximity of the reference determines howthe reference is generated from the parameter.
 22. The apparatus ofclaim 21, wherein the proximity of the reference can indicate that: theprogram element is located in the same class; the program element isassociated with another class in the same bundle; or the program elementis associated with another class in another bundle.
 23. The apparatus ofclaim 22, wherein if the program element is a field or a method, and ifthe proximity of the reference indicates that the program element islocated in the same class, the reference generation mechanism isconfigured to: use the parameter as an offset for the program elementwithin the same class.
 24. The apparatus of claim 22, wherein if theprogram element is a field or a method, and if the proximity of thereference indicates that the program element is located in another classin the same bundle, the reference generation mechanism is configured to:use the parameter to lookup an entry in a reference lookup structure,wherein the entry contains a global offset for the class, and an offsetfor the program element within the class.
 25. The apparatus of claim 22,wherein if the program element is a field or a method, and if theproximity of the reference indicates that the program element is locatedin another class in another bundle, the reference generation mechanismis configured to: use the parameter to lookup an entry in a referencelookup structure, wherein the entry identifies a class name, a programelement name and a program element type; use the class name to lookup aglobal offset for the class; and to use the program element name and theprogram element type to look up an offset for the program element withinthe class.
 26. The apparatus of claim 22, wherein if the program elementis a class, and if the proximity of the reference indicates that theclass is located in the same bundle, the reference generation mechanismis configured to: use the parameter to lookup an entry in a referencelookup structure, wherein the entry contains a global offset for theclass.
 27. The apparatus of claim 22, wherein if the program element isa class, and if the proximity of the reference indicates that the classis located in another bundle, the reference generation mechanism isconfigured to: use the parameter to lookup an entry in a referencelookup structure, wherein the entry identifies a class name; and to usethe class name to lookup a global offset for the class.
 28. Theapparatus of claim 21, further comprising a converter configured toconvert the platform-independent program into a form suitable forin-place execution; wherein prior to execution of theplatform-independent program, the converter is configured to produce areference lookup structure to facilitate generating references toprogram elements during in-place execution.
 29. The apparatus of claim28, wherein the reference lookup structure includes: a reference tablefor generating references to methods or fields; and an offset map forgenerating references to classes.
 30. The apparatus of claim 21, whereinthe information encoded within the parameter is contained in reservedbits, wherein the reserved bits are the two lowest-order bits of theparameter.
 31. A means for performing proximity-based addressing in aplatform-independent virtual machine, comprising: a receiving meanswithin the platform-independent virtual machine configured to receive,an instruction, and a parameter associated with the instruction that canbe used to generate a reference to a program element associated with theinstruction; and a reference generation means within theplatform-independent virtual machine configured to, examine informationencoded within the parameter to determine a proximity of the reference,and to use the parameter to generate the reference to the programelement, wherein the proximity of the reference determines how thereference is generated from the parameter.